package artid.com.arttogo.activity;
/**
 * 拍品搜索详情
 */

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.android.volley.VolleyError;

import java.util.ArrayList;
import java.util.List;

import artid.com.arttogo.R;
import artid.com.arttogo.adapter.AucOrgListAdapter;
import artid.com.arttogo.adapter.AuctionPastAuction_Adapter;
import artid.com.arttogo.adapter.LotListAdapter;
import artid.com.arttogo.adapter.SpecListAdapter;
import artid.com.arttogo.bean.AppItem;
import artid.com.arttogo.bean.AuctionAuctionListParser;
import artid.com.arttogo.bean.JigouList;
import artid.com.arttogo.bean.LotSearchDet;
import artid.com.arttogo.bean.SearchList;
import artid.com.arttogo.bean.Spinfo;
import artid.com.arttogo.db.Cache;
import artid.com.arttogo.network.VolleyBasic;
import artid.com.arttogo.network.VolleyCallback;
import artid.com.arttogo.network.VolleyData;
import artid.com.arttogo.network.VolleyMap;
import artid.com.arttogo.utils.NetUtils;

import static android.media.CamcorderProfile.get;

public class LotSearchDetActivity extends BaseActivity implements
		OnClickListener, OnItemClickListener {
	

	
	ListView mListLot;
	LotListAdapter mAdapterLot;
	SpecListAdapter mAdapterSpec;
	AucOrgListAdapter mAdapterOrg;
	AuctionPastAuction_Adapter mAdapterAuc;
	String type;
	String keyword;
	private String imgwide;// 请求的图片宽度
	private ArrayList<String> listLotIds=new ArrayList<>();//拍品ID集合，主要是实现可以左右滑动
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_lot_search_det);
		mContext = LotSearchDetActivity.this;
		getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
		imgwide = (Integer.parseInt(NetUtils.getDisplayMetrics((Activity) mContext).get(NetUtils.DM_WIDTH)) / 1) + "";
		mListLot = (ListView)findViewById(R.id.srh_det_list);
		// titleSearch.setOnClickListener(searchlistener());
		mTittle = (TextView)findViewById(R.id.tittle_text);
		mTittle.setText("搜索详情");
		mBack = (ImageView) findViewById(R.id.back_btn);
		mBack.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				finish();
			}
		});
		type = getIntent().getExtras().getString("type");
		keyword =  getIntent().getExtras().getString("keyword");
		reqData(keyword);
	}

	
	/**
	 * 请求网络
	 * @param keyword
	 */
	void reqData(String keyword){
		Class<? extends AppItem> itemclass = null;
		if (type.equals("4")) {
			itemclass = LotSearchDet.class;
		}
		if (type.equals("3")) {
			itemclass = Spinfo.class;
		}
		if (type.equals("2")) {
			itemclass =AuctionAuctionListParser.class;
		}
		if (type.equals("1")) {
			itemclass =JigouList.class;
		}
		VolleyBasic.getInstance((Activity)mContext).post(Cache.searchInfo,
				VolleyMap.getInstance().searchInfo("1", "100", keyword, type, "1",imgwide), itemclass,
				new VolleyCallback() {
					
					@Override
					public void onSuccess(VolleyData vd) {
						SearchList item = null ;
//						List<itemclass> item = vd.getList();
						if (type.equals("1")) {
							List<JigouList> itemlist = (List<JigouList>)vd.getList();
							mAdapterOrg = new AucOrgListAdapter(mContext);
							mAdapterOrg.setData(itemlist);
							mListLot.setAdapter(mAdapterOrg);
							mListLot.setOnItemClickListener(new OnItemClickListener() {

								@Override
								public void onItemClick(AdapterView<?> arg0,
														View arg1, int arg2, long arg3) {
									// TODO Auto-generated method stub
									Intent intent =new Intent(mContext,AucOrgDetActivity.class);
									intent.putExtra("id", mAdapterOrg.list.get(arg2).getId());
									startActivity(intent);
									
								}
							});
						}
						if (type.equals("2")) {
							List<AuctionAuctionListParser> itemlist = (List<AuctionAuctionListParser>)vd.getList();
							
							mAdapterAuc = new AuctionPastAuction_Adapter(mContext,itemlist);
							mListLot.setAdapter(mAdapterAuc);
							mListLot.setOnItemClickListener(new OnItemClickListener() {

								@Override
								public void onItemClick(AdapterView<?> arg0,
														View arg1, int arg2, long arg3) {
									// TODO Auto-generated method stub
									
									Intent intent =new Intent(mContext,AuctionInfo_Activity.class);
									intent.putExtra("auctionID", mAdapterAuc.list.get(arg2).getId());
									intent.putExtra("SpecialListData", 0);
									startActivity(intent);
								}
							});
						}
						if (type.equals("3")) {
                            //专场
							List<Spinfo> itemlist = (List<Spinfo>)vd.getList();
							mAdapterSpec = new SpecListAdapter(mContext);
							mAdapterSpec.setData(itemlist);
							mListLot.setAdapter(mAdapterSpec);
							mListLot.setOnItemClickListener(new OnItemClickListener() {

								@Override
								public void onItemClick(AdapterView<?> arg0,
														View arg1, int arg2, long arg3) {
									// TODO Auto-generated method stub
									Intent intent =new Intent(mContext,AuctionSpecialInfo_Activity.class);
									intent.putExtra("SpecialID", mAdapterSpec.list.get(arg2).getId());
									startActivity(intent);
									
								}
							});
						}
						if (type.equals("4")) {
                            //拍品
							List<LotSearchDet> itemlist = (List<LotSearchDet>)vd.getList();
							mAdapterLot = new LotListAdapter(mContext);
							mAdapterLot.setData(itemlist);
							mListLot.setAdapter(mAdapterLot);
							mListLot.setOnItemClickListener(new OnItemClickListener() {

								@Override
								public void onItemClick(AdapterView<?> arg0,
														View arg1, int arg2, long arg3) {
									// TODO Auto-generated method stub
									listLotIds.clear();
									for (int i = 0; i < mAdapterLot.list.size(); i++) {
										String idString = mAdapterLot.list.get(i).getId();
										listLotIds.add(idString);
									}
									Intent intent = new Intent(mContext, LotDetailPagerActivity.class);
									intent.putStringArrayListExtra("id", listLotIds);
									intent.putExtra("index", arg2);
									startActivity(intent);
								}
							});
						}	
					}
					@Override
					public void onError(VolleyError volleyError) {
						// TODO Auto-generated method stub
						
					}
					});
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.support.v4.app.FragmentActivity#onResume()
	 */
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		return true;
	}

	@Override
	public void onClick(View v) {

	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		// TODO Auto-generated method stub
		
	}

	
}
